//
//  HttpRequest_Curl.h
//  EZC_Library
//
//  Created by ellzu on 14-9-23.
//  Copyright (c) 2014年 ellzu. All rights reserved.
//

#ifndef __EZC_Library__HttpRequest_Curl__
#define __EZC_Library__HttpRequest_Curl__

#include <stdio.h>

#include <string>
#include "HttpRequestPlatformInterface.h"

#include "curl/curl.h"
#include "curl/easy.h"
#include <stdio.h>

namespace EZHttp {
    
    /**
     用LIB CURL 实现的http请求
     **/
    class HttpRequest_CURL : public HttpRequestPlatformInterface
    {
    public:
        HttpRequest_CURL();
    protected:
        virtual ~HttpRequest_CURL();
        
    public:
        //HttpRequestPlatformInterface
//        virtual void setUrl(const std::string &url);
//        virtual void setMethod(const std::string &method);
//        virtual void setRequestValue(const std::string &key,const std::string &value);
//        virtual void setHeader(const std::string &key,const std::string &value);
        
        virtual void startSync();
        virtual void startAsync();
        
    protected:
        
        CURL *_curl;
        
        void setupOption();
        std::string postValueToString();
        
        static size_t s_header_callback(char *buffer,   size_t size,   size_t nitems,   void *userdata);
        size_t header_callback(char *buffer,   size_t size,   size_t nitems);
        
        static size_t s_write_data(char *buffer,size_t size,size_t nitems,void *outstream);
        size_t write_data(char *buffer,size_t size,size_t nitems);
        
        static int s_progress_callback(void *clientp,double dltotal,double dlnow,double ultotal,double ulnow);
        int progress_callback(double dltotal,double dlnow,double ultotal,double ulnow);
        
        
    };
    
}

#endif /* defined(__EZC_Library__HttpRequest_Curl__) */
